<?php
namespace app\admin\controller\manager;

use app\admin\controller\Controller;
use app\admin\model\AdminRole as AdminRoleModel;

class Role extends Controller
{
    protected $model;
    /**
     * 初始化
     * @access public
     */
    public function initialize()
    {
        parent::initialize();
        // 控制器初始化
        $this->model = new AdminRoleModel;
    }

    // 角色列表
    public function index()
    {
        // 返回
       return $this->renderSuccess($this->model->getAll());
    }

    // 角色详细
    public function detail()
    {
        if($data = $this->model->detail($this->request->param('admin_role_id')))
        {
            return $this->renderSuccess($data ,'获取成功');
        }
        return $this->renderError($this->model->getError());
    }

    // 添加角色
    public function add()
    {
        if($this->model->add($this->request->only(['admin_menu_id', 'name','describe'])))
        {
            return $this->renderSuccess([],'新增成功');
        }
        return $this->renderError($this->model->getError());
    }

    // 编辑角色
    public function edit()
    {
        if($this->model->edit($this->request->only(['admin_role_id','admin_menu_id', 'name','describe'])))
        {
            return $this->renderSuccess([],'修改成功');
        }
        return $this->renderError($this->model->getError()??'修改失败');
    }

    // 删除角色
    public function delete()
    {

        if($this->model->remove($this->request->param('admin_role_id')))
        {
            return $this->renderSuccess([],'删除成功');
        }
        return $this->renderError($this->model->getError()??'删除失败');
    }
    
}